package com.qianyitian.hope2.analyzer.controller;


import com.dtflys.forest.annotation.Get;
import com.qianyitian.hope2.analyzer.config.PropertyConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

@RestController
public class PortfolioController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    PropertyConfig config;
    Properties p=new Properties();
    public PortfolioController() {
    }

    @GetMapping("/portfolio/profile/{portfolio}")
    @CrossOrigin
    public String demark(@PathVariable String portfolio) throws IOException {
        return p.getProperty(portfolio);
    }

    @PostConstruct
    public void init() throws IOException {
        p.load(new FileReader(new File(config.getDataPath(),"portfolio-profile")));
    }
}
